package com.ktjiaoyu.crm.controller;
import com.ktjiaoyu.crm.pojo.User;
import com.ktjiaoyu.crm.service.UserService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

@RestController
public class UserController {

    @Resource
    private UserService userService;

    //按照RESTFUL思想
    @GetMapping(value = "/users")
    public List<User> findAllUsers(){
        List<User> list = userService.findAllUsers();
        return list;
    }

    @GetMapping(value = "/user/{id}")
    public User getUser(@PathVariable("id")Long usrId){
        User user = userService.getUser(usrId);
        return user;
    }

    @PostMapping(value = "/user")
    public void addUser(User user){
        userService.addUser(user);
    }

    @PutMapping(value = "/user")
    public void updateUser(User user){
        userService.updateUser(user);
    }

    @DeleteMapping(value = "/user/{id}")
    public void deleteUser(@PathVariable("id")Long usrId){
        userService.deleteUser(usrId);
    }


//    @RequestMapping(value = "/getUser",method = RequestMethod.GET)
//       public User getUser(Long usrId){
//     User user = userService.getUser(usrId);
//        return user;
//}

}
